package com.bkgrands.fpmu.Adapters;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bkgrands.fpmu.R;
import com.bkgrands.fpmu.activities.ProgressDetailsActivity;
import com.bkgrands.fpmu.classes.Photo;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jeff on 7/17/19.
 */

public class ProgressAdapter extends RecyclerView.Adapter<ProgressAdapter.ViewHolder> {
    public List<Photo> photo;
    Context context;
    public static final String EXTRA_IMG = "imageUrl";
    public static final String EXTRA_CAP = "image_caption";
    public ProgressAdapter(Context context,List<Photo>photo){
        this.photo = photo;
        this.context=context;
    }


    @Override
    public ProgressAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.photoprogressrecycler, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ProgressAdapter.ViewHolder viewHolder, final int i) {
        viewHolder.caption.setText(photo.get(i).getDescription());
        Picasso.get().load(photo.get(i).getPhoto()).into(viewHolder.photo);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), ProgressDetailsActivity.class);
                intent.putExtra(EXTRA_CAP,String.valueOf(photo.get(i).getDescription()) );
                intent.putExtra(EXTRA_IMG,photo.get(i).getPhoto());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
       return photo.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView caption;
        private ImageView photo;
        public ViewHolder(View view) {
            super(view);
            caption = (TextView)view.findViewById(R.id.caption);
            photo = (ImageView)view.findViewById(R.id.project_image);
        }
    }
}
